﻿using MediatR;
using System.CJL.API.Application.Command.RawMaterialCommand;
using System.CJL.Infrstructre.Interface;

namespace System.CJL.API.Application.CommandHanlder.RawMaterialCommandHanler
{
    /// <summary>
    /// 原料删除
    /// </summary>
    public class RawMaterialDeleteCommandHandler : IRequestHandler<RawMaterialDeleteCommand, int>
    {
        IRawMaterialRepository _repository;
        /// <summary>
        /// 构造函数
        /// </summary>
        public RawMaterialDeleteCommandHandler(IRawMaterialRepository repository)
        {
            _repository = repository;
        }
        /// <summary>
        /// 原料删除
        /// </summary>
        public async Task<int> Handle(RawMaterialDeleteCommand request, CancellationToken cancellationToken)
        {
            var arr = await _repository.GetMondel(request.Id);
            arr.IsDelete = true;
            arr.DelectTime = DateTime.Now.ToUniversalTime();
            arr.DelectName = "张三";
            await _repository.UpdateAsync(arr);
            return 1;
        }
    }
}
